<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>
        <ui:composition template="./../../Template/generalTemplate.xhtml">
            <ui:define name="content">
                <p:panel id="supplierMgt" header="Manage Suppliers" style="height:495px;">
                    <div style="margin-top:20px;margin-left:10px;margin-right:10px;">
                        <h:form id="form">
                            <f:view beforePhase="#{manageSupplierManagedBean.initView}">
                            <p:growl id="msgs" showDetail="true" /> 
                            <p:dataTable id="suppliers" value="#{manageSupplierManagedBean.getSuppliers()}" var="supplierList" paginator="true" rows="5">

                                <p:column headerText="ID" filterBy="#{supplierList.id}" filterMatchMode="contains">
                                    <h:outputText value="#{supplierList.id}"/>
                                </p:column>
                                <p:column headerText="Supplier" filterBy="#{supplierList.supplierName}" filterMatchMode="contains">
                                    <h:outputText value="#{supplierList.supplierName}"/>
                                </p:column>
                                <p:column headerText="Phone Number" filterBy="#{supplierList.phoneNumber}" filterMatchMode="contains">
                                    <h:outputText value="#{supplierList.phoneNumber}"/>
                                </p:column>
                                
                                <p:column headerText="Email" filterBy="#{supplierList.emailAddress}" filterMatchMode="contains">
                                    <h:outputText value="#{supplierList.emailAddress}"/>
                                </p:column>
                                <p:column headerText="Contact Person" filterBy="#{supplierList.contactPersonName}" filterMatchMode="contains">
                                    <h:outputText value="#{supplierList.contactPersonName}"/>
                                </p:column>
                                
                                <p:column headerText="Address" style="text-align: center;">
                                    <p:commandButton update="form:outputPanelMain" oncomplete="carDialog.show()" value="View">  
                                        <f:setPropertyActionListener value="#{supplierList}" target="#{manageSupplierManagedBean.selectedSupplier}" />  
                                    </p:commandButton>
                                </p:column>
                                
                                <p:column headerText="Action" style="text-align: center;">                                          
                                        <p:commandButton action ="#{manageSupplierManagedBean.editSupplier(supplierList)}" image="ui-icon ui-icon-pencil" title="Edit" /> 
                                        
                                        <p:commandButton style="margin-left: 10px;" update=":form:display" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete" rendered="#{manageSupplierManagedBean.canDelete}">  
                                            <f:setPropertyActionListener value="#{supplierList}" target="#{manageSupplierManagedBean.selectedSupplier}" />  
                                        </p:commandButton>  
                                </p:column>  

                            </p:dataTable>

                            <p:dialog header="Address" widgetVar="carDialog" resizable="false" id="carDlg"  
                                      showEffect="fade" hideEffect="explode" modal="true" width="500">  
                                
                              <p:outputPanel id="outputPanelMain">
                                
                                <h:panelGrid id="display"  columns="2" cellpadding="4">  
                                    <h:outputText value="Supplier Address" style="font-weight:bold"/>  
                                    <h:outputText value="#{manageSupplierManagedBean.selectedSupplier.address.streetName}" />
                                    <br />
                                    <h:outputText value="#{manageSupplierManagedBean.selectedSupplier.address.city}" />
                                    <br />
                                    <h:outputText value="#{manageSupplierManagedBean.selectedSupplier.address.postCode}" />
                                </h:panelGrid>
                                
                              </p:outputPanel>

                            </p:dialog>
                            
                            
                            <p:confirmDialog message="Are you sure?" width="200"  
                                             showEffect="explode" hideEffect="explode"  
                                             header="Confirm" severity="alert" widgetVar="confirmation">  

                                <p:commandButton value="Yes" update="suppliers" actionListener="#{manageSupplierManagedBean.deleteSupplier}" oncomplete="confirmation.hide()">  
                                    <f:attribute name="param1" value="#{manageSupplierManagedBean.selectedSupplier.id}" />
                                </p:commandButton>
                                <p:commandButton value="Not yet" onclick="confirmation.hide()" type="button" />  

                            </p:confirmDialog>  
                            </f:view>
                        </h:form>  
                    </div>
                </p:panel>
            </ui:define>
        </ui:composition>
    </body>
</html>